<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{% block title %}维修管理系统{% endblock %}</title>
    <!-- Bootstrap 5 CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- Bootstrap Icons -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.1/font/bootstrap-icons.css">
    <!-- Bootstrap 5 JS -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
    <style>
        .content {
            background: white;
            padding: 30px;
            margin: 20px 0;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
    </style>
</head>
<body>
    <nav class="navbar navbar-expand-lg navbar-dark bg-primary">
        <div class="container-fluid">
            <a class="navbar-brand" href="{% url 'home' %}">
                <i class="bi bi-tools"></i> 维修管理系统
            </a>
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarNav">
                {% if user.is_authenticated %}
                <ul class="navbar-nav me-auto">
                    <!-- 通用菜单 -->
                    <li class="nav-item">
                        <a class="nav-link" href="{% url 'dashboard' %}">
                            <i class="bi bi-speedometer2"></i> 仪表板
                        </a>
                    </li>
                    
                    <!-- 管理员菜单 -->
                    {% if user.profile.role == 'admin' or user.is_staff %}
                    <li class="nav-item">
                        <a class="nav-link" href="{% url 'users:user_list' %}">
                            <i class="bi bi-people"></i> 用户管理
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="{% url 'assets:asset_manage' %}">
                            <i class="bi bi-pc-display"></i> 设备管理
                        </a>
                    </li>
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown">
                            <i class="bi bi-box-seam"></i> 备件管理
                        </a>
                        <ul class="dropdown-menu">
                            <li><a class="dropdown-item" href="{% url 'spare_parts:sku_management' %}">SKU管理</a></li>
                            <li><a class="dropdown-item" href="{% url 'spare_parts:inventory_list' %}">库存管理</a></li>
                            <li><a class="dropdown-item" href="{% url 'spare_parts:purchase_list' %}">采购管理</a></li>
                            <li><a class="dropdown-item" href="{% url 'spare_parts:supplier_list' %}">供应商管理</a></li>
                            <li><a class="dropdown-item" href="{% url 'spare_parts:category_list' %}">分类管理</a></li>
                            <li><a class="dropdown-item" href="{% url 'spare_parts:usage_list' %}">使用记录</a></li>
                        </ul>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="{% url 'tickets:ticket_list_all' %}">
                            <i class="bi bi-list-check"></i> 工单管理
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="{% url 'notifications:notification_list' %}">
                            <i class="bi bi-bell"></i> 通知管理
                        </a>
                    </li>
                    {% endif %}
                    
                    <!-- 技术人员菜单 -->
                    {% if user.profile.role == 'technician' %}
                    <li class="nav-item">
                        <a class="nav-link" href="{% url 'tickets:ticket_list_assigned' %}">
                            <i class="bi bi-clipboard-check"></i> 我的工单
                        </a>
                    </li>
                    {% endif %}
                    
                    <!-- 前台菜单 -->
                    {% if user.profile.role == 'receptionist' %}
                    <li class="nav-item">
                        <a class="nav-link" href="{% url 'tickets:ticket_list_all' %}">
                            <i class="bi bi-list-check"></i> 工单管理
                        </a>
                    </li>
                    {% endif %}

                    <!-- 质检员菜单 -->
                    {% if user.profile.role == 'quality_checker' %}
                    <li class="nav-item">
                        <a class="nav-link" href="{% url 'tickets:ticket_list_quality_checker' %}">
                            <i class="bi bi-list-check"></i> 工单管理
                        </a>
                    </li>
                    {% endif %}

                    <!-- 客户菜单 -->
                    {% if user.profile.role == 'customer' or not user.profile.role %}
                    <li class="nav-item">
                        <a class="nav-link" href="{% url 'tickets:ticket_list_mine' %}">
                            <i class="bi bi-list-check"></i> 我的工单
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="{% url 'tickets:ticket_create' %}">
                            <i class="bi bi-plus-circle"></i> 创建工单
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="{% url 'assets:asset_list_mine' %}">
                            <i class="bi bi-device-ssd"></i> 我的设备
                        </a>
                    </li>
                    {% endif %}
                    
                    <!-- 通用功能 - 只对管理员、技术人员、客户显示 -->
                    {% if user.profile.role == 'admin' or user.profile.role == 'technician' or user.profile.role == 'customer' or user.is_staff %}
                    <li class="nav-item">
                        <a class="nav-link" href="{% url 'reports' %}">
                            <i class="bi bi-bar-chart"></i> 报表统计
                        </a>
                    </li>
                    {% endif %}
                    
                    <!-- 管理员后台入口 -->
                    {% if user.is_staff %}
                    <li class="nav-item">
                        <a class="nav-link" href="/admin/">
                            <i class="bi bi-gear"></i> 管理后台
                        </a>
                    </li>
                    {% endif %}
                </ul>
                <ul class="navbar-nav">
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown">
                            <i class="bi bi-person-circle"></i> {{ user.username }}
                        </a>
                        <ul class="dropdown-menu dropdown-menu-end">
                            <li><span class="dropdown-item-text">角色: {{ user.profile.get_role_display }}</span></li>
                            <li><hr class="dropdown-divider"></li>
                            <li>
                                <form method="post" action="{% url 'logout' %}" style="display: inline;">
                                    {% csrf_token %}
                                    <button type="submit" class="dropdown-item" style="border: none; background: none; text-align: left; width: 100%;">
                                        <i class="bi bi-box-arrow-right"></i> 退出
                                    </button>
                                </form>
                            </li>
                        </ul>
                    </li>
                </ul>
                {% else %}
                <ul class="navbar-nav ms-auto">
                    <li class="nav-item">
                        <a class="nav-link" href="{% url 'login' %}">
                            <i class="bi bi-box-arrow-in-right"></i> 登录
                        </a>
                    </li>
                </ul>
                {% endif %}
            </div>
        </div>
    </nav>

    <div class="container">
        <div class="content">
            {% block content %}
            {% endblock %}
        </div>
    </div>
</body>
</html>
